/*
============================================================================
Name		: Control.h
Author	  : emoney
Version	 : 1.0
Copyright   :
Description : CControl declaration
============================================================================
*/

#ifndef CONTROL_H
#define CONTROL_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <bitstd.h>		//CFbsBitGc
#include <BADESCA.H>
//#include "eStockMainGridContainer.h"
// CLASS DECLARATION


class CControl : public CBase
{
public:
	virtual ~CControl();
	CControl();
	
public:
	virtual void Draw(CFbsBitGc&  g);

	virtual void SetRect(const TInt& left,const TInt& top,const TInt& right, const TInt& bottom);

	virtual TBool OnKeyDown(const TInt& keycode);

	virtual TBool OnMouseDown(const TPoint& aPt);

	virtual TBool OnMouseMove(const TPoint& aPt);

	virtual TBool OnMouseUp(const TPoint& aPt);

	virtual TBool Focus() {return iFocus;}

	virtual void SetFocus(TBool aFocus, const TInt keyCode = 0);

	virtual void FocusChanged(TBool aFocus, const TInt keyCode = 0);

public:
	TBool m_bHidden;
	TRect m_rect;
	CControl* m_pParent;
	TBool iFocus;
};

class CCheckBox : public CControl
{
public:
	~CCheckBox();
	static CCheckBox* NewL(const TDesC& aDes);
	static CCheckBox* NewLC(const TDesC& aDes);
	void ConstructL();

public:
	//from Base Class
	virtual void Draw(CFbsBitGc&  g);

	virtual TBool OnKeyDown(const TInt& keycode);

private:
	CCheckBox(const TDesC& aDes);

private:
	TBuf<8>	m_strText;
	TBuf<2> m_strCheck;
	TRgb m_rgbBorder;
	TRgb m_rgbBorderActive;
public:
	TBool m_bLock;
	TInt m_nXLock;
	TInt m_nYLock;
};

class CSlider:public CControl
{
public:
	~CSlider();
	static CSlider* NewL(const TDesC& aName,const TInt& aVal,const TInt aMax,const TInt aMin);
	static CSlider* NewLC(const TDesC& aName,const TInt& aVal,const TInt aMax,const TInt aMin);
	void ConstructL();

public:
	//from Base Class
	virtual void Draw(CFbsBitGc&  g);

	virtual TBool OnKeyDown(const TInt& keycode);

	void SetRect(const TInt& left,const TInt& top,const TInt& right, const TInt& bottom);

	virtual TBool OnMouseDown(const TPoint& aPt);

	virtual TBool OnMouseMove(const TPoint& aPt);

public:
	TInt GetValue(){return m_nValue;}

private:
	CSlider(const TDesC& aName,const TInt& aVal,const TInt aMax,const TInt aMin);

private:
	TBuf<8>	m_strText;
	TInt	m_nValue;
	TInt	m_nMax;
	TInt	m_nMin;

	TRect	m_rectSlider;
	TBool	m_bSlidPressed;
	TInt	m_nSldLeft;
	TInt	m_nSldRight;
};

class TSelectItem
{
public:
	TInt m_nID;
	TBuf<16> m_strName;
};

class CSelectBox : public CControl
{
public:
	~CSelectBox();
	static CSelectBox* NewL();
	static CSelectBox* NewLC();
	void ConstructL();

public:
	//from Base Class
	virtual void Draw(CFbsBitGc&  g);

	virtual TBool OnKeyDown(const TInt& keycode);

	virtual void SetRect(const TInt& left,const TInt& top,const TInt& right, const TInt& bottom);
public:
	//new function
	void AddItem(const TInt& aId,const TInt& aResID);
	void AddItem(const TInt& aId,const TDesC16& aText);
	void RemoveAll();
	
	TBool SetCurValue(TInt nValue);
	TInt GetCurValue();
	
	inline TInt GetCurIndex(){return m_curIntex;};
	inline void SetCurIndex(const TInt& aInd){m_curIntex = aInd;}
	
	inline TInt GetItemCount(){return m_items.Count();}
	
	TBool GetCurText(TDes& text);
	TBool GetCurText(TDes8& text);
	
protected:
	CSelectBox();
	
protected:
	RArray<TSelectItem> m_items;
	TInt m_curIntex;
	TRgb m_rgbBorder;
	TRgb m_rgbBorderActive;
	TRgb m_rgbBg;
	TRect m_rectLeft;
	TRect m_rectRight;
};

class CRadioBox: public CSelectBox
{
public:
	~CRadioBox();
	static CRadioBox* NewL();
	static CRadioBox* NewLC();
	void ConstructL();
	
public:
	//from Base Class
	virtual void Draw(CFbsBitGc&  g);
	virtual void SetRect(const TInt& left,const TInt& top,const TInt& right, const TInt& bottom);

public:
	virtual TBool OnMouseUp(const TPoint& aPt);
	
public:
	CRadioBox();
};

class CLabelSelectBox : public CSelectBox
{
public:
	~CLabelSelectBox();
	static CLabelSelectBox* NewL(const TDesC& aName);
	static CLabelSelectBox* NewLC(const TDesC& aName);
	void ConstructL();

public:
	//from Base Class
	virtual void Draw(CFbsBitGc&  g);
	virtual void SetRect(const TInt& left,const TInt& top,const TInt& right, const TInt& bottom);
	
	void SetLabelWidthInPixels(TInt aWidth);
	
public:
	virtual TBool OnMouseUp(const TPoint& aPt);
	
private:
	CLabelSelectBox(const TDesC& aName);
	
public:
	TRect m_DisplayRect;
	
private:
	TBuf<16> m_strLabel;
	TInt iLabelWidthInPixels; 
};

class MRepeatOverObserver
{
public:
	virtual void RepeatOver() = 0;
};

class CTextInput:public CControl
{
public:
	enum TInputType
	{
		NUMERIC = 1,
		INTEGER = 2,
		PASSWORD = 4,
		LETTER = 8,
		STOCK = 16,
		REAL = 32,
		ZN = 64,
	};

public:
	~CTextInput();
	CTextInput(const TInt& aMaxLen);
	static CTextInput* NewL(const TInt& aMaxLen);
	static CTextInput* NewLC(const TInt& aMaxLen);
	void ConstructL();

public:
	//from Base Class
	virtual void Draw(CFbsBitGc&  g);

	virtual TBool OnKeyDown(const TInt& keycode);
	
	void SetFocus(TBool aFocus, const TInt keyCode = 0);

public:
	void StartKeyboard();

	void StopKeyboard();

	static TInt OnKeyboard(TAny* aAny);

public:
	//new function
	void GetText(TDes& aDes);
	void GetText(TDes8& aDes);
	void SetText(const TDesC& aDes);
	void SetText(const TDesC8& aDes8);
	void SetEnabled(TBool aEnabled) {iEnabled = aEnabled;}

public:
	TBuf<128> m_pbInput;//
	TBuf<128> m_strEmpty;//
	TInt m_nMaxLen;
	TBool m_bNumber;
	TInt8 m_bStation;
	TInt m_nLastInput;
	TInt m_nInputType;
	CPeriodic* m_threadKeyboard;

	TInt m_nMin;
	TInt m_nMax;
	
	TReal m_dMin;
	TReal m_dMax;

	TRgb m_rgbBorder;
	TRgb m_rgbBorderActive;
	TRgb m_rgbBg;

	TInt m_CodeTrans[10];

	MRepeatOverObserver* iObserver;
	TBool iEnabled;
};

class CTextInputControl: public CControl
{
friend class CSingleLineTextInput;
friend class CStockTextInput;
friend class CDisplayInputText;
public:
	~CTextInputControl();
	//	void ConstructL();
public:
	void SetFocus(TBool aFocus, const TInt keyCode = 0);
	TBool Focus();

	void GetText(TDes& aText);
	void GetText(TDes8& aText);

	void SetText(const TDesC& aDes);
	void SetText(const TDesC8& aDes8);

	TInt GetMaxLength();
	TInt GetTextLength();

	void SetEmtpyString(const TDesC& aDes);

	TBool IsNumber();
	
	void SetNumber(TBool bNumber);
	void SetHide(TBool bVisible);

	TInt8 GetStation();
	void SetStation(TInt8 bStation);

	TInt GetIntValue();
	void SetInputTpye(const TInt aType);
	void SetEnabled(TBool aEnabled);
	TBool GetEnabled();
	
private:
	CTextInputControl();
	
protected:
	CTextInput* m_textInput;
};

class CSingleLineTextInput : public CTextInputControl
{
public:
	CSingleLineTextInput(const TDesC& aName, const TInt& aMaxLen);
	~CSingleLineTextInput();
	
	static CSingleLineTextInput* NewL(const TDesC& aName, const TInt& aMaxLen);
	static CSingleLineTextInput* NewLC(const TDesC& aName, const TInt& aMaxLen);
	
	void ConstructL(const TInt& aMaxLen);
	
	CTextInput* GetTextInput() {return m_textInput;}
	void SetLabel(const TDesC& aLabel) { m_strLabel.Copy(aLabel);}
	
public:
	void SetTitle(const TDesC& buf);
	void SetRange(const TInt& nMin, const TInt& nMax);
	void SetRange(const TReal& nMin, const TReal& nMax);
	void SetTypeDecimal(TBool b = ETrue);

	void SetRect(const TInt& left,const TInt& top,const TInt& right, const TInt& bottom);
	void Draw(CFbsBitGc& g);
	TBool OnKeyDown(const TInt& keyCode);
	void SetLabelWidthInPixels(TInt aWidth);
	
protected:
	TBuf<16> m_strLabel;
	TInt iLabelWidthInPixels;
	TBool m_bTextHidden;
};

class CSingleLineAllTextInput : public CSingleLineTextInput
{
public:
	CSingleLineAllTextInput(const TDesC& aName, const TInt& aMaxLen);
	~CSingleLineAllTextInput();
	
	static CSingleLineAllTextInput* NewL(const TDesC& aName, const TInt& aMaxLen);
	static CSingleLineAllTextInput* NewLC(const TDesC& aName, const TInt& aMaxLen);
	
	void ConstructL(const TInt& aMaxLen);
	
	TBool OnKeyDown(const TInt& keyCode);
	
	TBool OnMouseUp(const TPoint& aPt);
};

class CDisplayInputText : public CTextInputControl
{
public:
	static CDisplayInputText* NewL();
	static CDisplayInputText* NewLC();
	~CDisplayInputText();
	
public:
	void OnSize();
	void Draw(CFbsBitGc& g);
	TBool SetSingleLineInput(CControl* pInput);
	void SetHidden(TBool b);
	
private:
	CDisplayInputText();
	void ConstructL();
	
private:
	TBool m_bIsHidden;
	CSingleLineTextInput*	m_pSingleLineInput;
public:
	
	inline TBool GetHidden(){return m_bIsHidden;};
};

class MRepeatOverNotifier
{
public:
	virtual void RepeatOver() = 0;
};

class CStockTextInput:public CTextInputControl, public MRepeatOverObserver
{
public:
	static CStockTextInput* NewL();
	static CStockTextInput* NewLC();
	
	~CStockTextInput();
	
	void RepeatOver();
	void SetObserver(MRepeatOverNotifier* aObserver);
	
public:
	void OnSize();
	void Draw(CFbsBitGc& g);
	TBool OnKeyDown(int keyCode);
	
private:
	CStockTextInput();
	void ConstructL();

private:
	TRect m_rectTop;
	MRepeatOverNotifier* iObserver;

	CFbsBitmap* m_searchBmp;
	CFbsBitmap* m_searchMaskBmp;
};

class MPushButtonObserver
{
public:
    virtual void PushButtonClicked() = 0;
};

class CPushButton : public CControl
{
public:
    ~CPushButton();
    static CPushButton* NewL(MPushButtonObserver* aObserver);
    static CPushButton* NewLC(MPushButtonObserver* aObserver);
    
private:
    CPushButton(MPushButtonObserver* aObserver);
    void ConstructL();
    
public:
    void Draw(CFbsBitGc& g);
    
    TBool OnMouseDown(const TPoint& aPt);
    TBool OnMouseUp(const TPoint& aPt);
    TBool OnKeyDown(const TInt& keycode);
    
public:
    void SetText(const TDesC& aText);
    
private:
    TBuf<8> iText;
    MPushButtonObserver* iObserver;
};

#endif // CONTROL_H
